/**
 * 
 */
package ar.com.sebasoft.prestalibro.view.fragment.socio;

import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ListView;
import ar.com.sebasoft.prestalibro.R;
import ar.com.sebasoft.prestalibro.model.Libro;
import ar.com.sebasoft.prestalibro.util.SystemHelper;
import ar.com.sebasoft.prestalibro.view.adapter.LibroListAdapter;
import ar.com.sebasoft.prestalibro.view.fragment.BaseFragment;

import com.androidquery.AQuery;

/**
 * @author SebaSOFT
 * 
 */
public class SocioListFragment extends BaseFragment {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_abm_list, container, false);

		return rootView;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);

		AQuery aq = new AQuery(this.getView());

		aq.find(R.id.lstABMItems).adapter(this.obtenerLibroAdapter());
		aq.find(R.id.lblListTitle).text(SystemHelper.getLocalizedString(R.string.lbl_abm_lista, "Libros"));
		ListView lst = aq.find(R.id.lstABMItems).getListView();
		aq.find(R.id.lblListRecords).text(SystemHelper.getLocalizedString(R.string.lbl_abm_records, lst.getAdapter().getCount()));
	}

	private Adapter obtenerLibroAdapter() {

		List<Libro> libros = this.getSession().getDbHelper().getLibroDao().queryForAll();

		Adapter res = new LibroListAdapter(this.getActivity().getApplicationContext(), R.id.lblListTitle, libros);
		return res;
	}
}